package com.example.demo.controller;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class RabbitMQController {

	@Autowired
	private AmqpTemplate template;

	@RequestMapping("send")
	public void send() {

//		UserDomain user=new UserDomain();    //实现Serializable接口
//        user.setUserName("hlhdidi");
//        user.setPassword("123");
//		template.convertAndSend("queue", user);

		// 消息队列模式
//		template.convertAndSend("queue", "hello,rabbit~");

		// 订阅者模式(通配符模式)
//		template.convertAndSend("exchange","topic.messages" ,"hello,rabbit~");

		// 订阅者模式(Fanout广播)
//		template.convertAndSend("fanoutExchange", "", "haha,heihei");// 第二个参数,无效,直接都有分

		// 订阅模式(Direct定向)
		template.convertAndSend("directExchange", "fanout.B", "hello,rabbit~");
	}
}
